<!--
 * @Descripttion: 
 * @version: 
 * @Author: ruxiang.wang
 * @Date: 2021-06-04 17:06:37
 * @LastEditors: ruxiang.wang
 * @LastEditTime: 2021-07-02 20:20:22
-->
<template>
  <div class="app-container">
    <!-- 搜索查询 -->
    <div class="list-search">
      <el-row :gutter="20">
        <el-col :span="6">
          <span class="list-search-tip">单元名称：</span>
          <el-input
            class="list-search-input"
            placeholder="请输入内容"
            v-model="listQuery.name">
          </el-input>
        </el-col>
        <el-col :span="6">
          <span class="list-search-tip">部署方案：</span>
          <el-select class="list-search-input" v-model="listQuery.deploymentPlan" :multiple="true" filterable placeholder="请选择">
            <el-option
              v-for="item in deploymentPlanOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="12">
          <el-button type="primary" icon="el-icon-search" @click="listSearch">搜索</el-button>
        </el-col>
      </el-row>
    </div>
    <!-- 新建 -->
    <div class="list-add">
      <el-button type="primary" icon="el-icon-document-add" @click="addData">新建</el-button>
      <el-button size="medium" type="primary" @click="jumpOther">新增(跳转界面)</el-button>
    </div>
    <!-- 表格 -->
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        align="center"
        label="序号"
        type="index"
        :index="indexMethod"
        width="50">
      </el-table-column>
      <el-table-column
        prop="tabName"
        label="tab名称"
        show-overflow-tooltip
        width="120">
      </el-table-column>
      <el-table-column
        prop="deploymentPlan"
        label="部署方案"
        show-overflow-tooltip
        width="280">
      </el-table-column>
      <el-table-column
        prop="order"
        label="顺序">
        <template slot-scope="scope">
          <!-- <el-input disabled v-model="scope.row.order" placeholder="请输入顺序值"></el-input> -->
          <span>{{scope.row.order}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="function"
        label="功能"
        show-overflow-tooltip
        width="280">
      </el-table-column>
      <el-table-column
        prop="state"
        label="发布状态"
        width="100">
        <template slot-scope="scope">
          <span
            v-if="scope.row.state =='0'"
            style="color:red;"
          >未发布</span>
          <span
            v-if="scope.row.state =='1'"
            style="color:green;"
          >已发布</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="180">
        <template slot-scope="scope">
          <el-button v-if="scope.row.state =='0'" type="text" size="small" @click="edit(scope.row)">编辑</el-button>
          <el-button v-if="scope.row.state =='0'" type="text" size="small" @click="adjustTheOrder(scope.row)">调整顺序</el-button>
          <el-button type="text" size="small" @click="copy(scope.row)">复制</el-button>
          <el-button v-if="scope.row.state =='0'" type="text" size="small" @click="del(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="paging" v-if="tableData.length>0">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40, 50]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
    <!-- 新建单元、编辑单元弹窗 -->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      width="50%">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="方案名称" prop="tabName">
          <el-input v-model="ruleForm.tabName"></el-input>
        </el-form-item>
        <el-form-item label="部署方案" prop="deploymentPlan">
          <el-select style="width:100%;" v-model="ruleForm.deploymentPlan" :multiple="true" placeholder="请选择部署方案">
            <el-option
              v-for="item in deploymentPlanOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="功能配置" prop="model">
          <el-button size="medium" type="primary" @click="innerVisible=true">新增</el-button>
        </el-form-item>
        <!-- 功能配置数据表格 -->
        <el-table
          v-if="tableDataFun.length>0"
          :data="tableDataFun"
          border
          style="width: 100%;margin-top:20px;">
          <el-table-column
            prop="nameInner"
            label="功能"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="nameInner"
            label="功能主题"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="nameInner"
            label="封面图">
            <template slot-scope="scope">
              <el-image
                v-if="scope.row.imageUrl !==''"
                style="width: 120px; height: 80px"
                :src="scope.row.imageUrl"
                fit="fill">
              </el-image>
              <span
                v-else
                style="color:green;"
              >暂无封面图</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            width="180">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="delFun(scope.row)">编辑</el-button>
              <el-button type="text" size="small" @click="delFun(scope.row)">上移</el-button>
              <el-button type="text" size="small" @click="delFun(scope.row)">下移</el-button>
              <el-button type="text" size="small" @click="delFun(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 功能配置（新增/编辑）第二层弹窗 -->
        <el-dialog
          width="45%"
          title="功能配置（新增/编辑）"
          :visible.sync="innerVisible"
          :close-on-click-modal="false"
          append-to-body>
          <el-form :model="ruleForm1" :rules="rules1" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="功能名称" prop="name">
              <el-input v-model="ruleForm1.name"></el-input>
            </el-form-item>
            <el-form-item label="封面图片" prop="region">
              
            </el-form-item>
            <el-form-item label="主题" prop="title">
              
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="innerVisible=false">取 消</el-button>
            <el-button type="primary" @click="innerVisible=false">确 定</el-button>
          </span>
        </el-dialog>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible=false">取 消</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 调整顺序弹窗 -->
    <el-dialog
      title="tab顺序调整"
      :visible.sync="dialogVisible1"
      :close-on-click-modal="false"
      width="50%">
      <el-form :model="ruleForm1" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="方案名称" prop="tabName">
          <el-input disabled v-model="ruleForm1.tabName"></el-input>
        </el-form-item>
        <!-- 表格 -->
        <el-table
          :data="tableData"
          border
          style="width: 100%">
          <el-table-column
            align="center"
            label="序号"
            type="index"
            :index="indexMethod"
            width="50">
          </el-table-column>
          <el-table-column
            prop="tabName"
            label="tab名称"
            show-overflow-tooltip
            width="200">
          </el-table-column>
          <el-table-column
            prop="function"
            label="功能">
          </el-table-column>
          <el-table-column
            label="操作"
            width="180">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="copy(scope.row)">上移</el-button>
              <el-button type="text" size="small" @click="copy(scope.row)">下移</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible1=false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible1=false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
//引入富文本编辑器组件
import Tinymce from '@/components/tinymce/index'

export default {
  components: {
    'editor': Tinymce
  },
  data() {
    return {
      // 搜索条件
      listQuery:{
        name:'',
        deploymentPlan:'',
      },
      // 部署方案下拉框数据
      deploymentPlanOptions:[{
        value: 'chinese',
        label: '部署方案1'
      }, {
        value: 'usa',
        label: '部署方案2'
      }],
      // 表格数据
      tableData: [{
        tabName: '王小虎',
        deploymentPlan:'方案部署1、方案部署2',
        order: '1',
        function: '普陀区、上海市普陀区金沙江路 1518 弄',
        state:'0',
      },{
        tabName: '王小虎',
        deploymentPlan:'方案部署1、方案部署2',
        order: '1',
        function: '普陀区、上海市普陀区金沙江路 1518 弄',
        state:'1',
      }],
      // 分页
      currentPage: 1,
      total:100,
      // 新建单元、编辑单元弹窗
      dialogTitle:'',
      dialogVisible: false,
      ruleForm: {
        tabName: '',
        deploymentPlan: '',
        model:'',
      },
      rules: {
        tabName: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        deploymentPlan: [
          { required: true, message: '请选择部署方案', trigger: 'change' }
        ],
        model: [
          { required: true, message: '请选择部署方案', trigger: 'change' }
        ],
      },
      tableDataFun:[{
        nameInner: 'TCL',
        codeInner: '20160502',
        imageUrl:'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
      }],
      // tab顺序调整弹窗
      dialogVisible1:false,
      ruleForm1: {
        name: '',
        deploymentPlan: '',
      },
      // 功能配置（新增/编辑）第二层弹窗
      innerVisible:false,
      ruleForm1: {
        name: '',
        region: '',
        model: ''
      },
      rules1: {
        name: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        region: [
          { required: true, message: '请选择部署国家', trigger: 'change' }
        ],
        model: [
          { required: true, message: '请选择生效机型', trigger: 'change' }
        ],
      },
    }
  },
  watch: {
    filterText(val) {
      this.$refs.tree2.filter(val)
    }
  },

  created(){
    // debugger
  },

  methods: {
    // 跳转其他路由界面
    jumpOther(row) {
      this.$router.push({ path: '/editOrAdd/index', params: { userId: 'ruxiang.wang' }}) //带参跳转
    },
    // 表格序号
    indexMethod(index) {
      return index+1;
    },
    // 搜索
    listSearch(){
      console.log(this.listQuery.name+'==='+this.listQuery.deploymentPlan);
    },
    // 新建
    addData(){
      this.dialogTitle='新建';
      this.ruleForm={};
      this.dialogVisible=true;
    },
    // 分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    // 复制
    copy(row) {
      this.$confirm('是否确定复制该数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '复制成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消复制'
        });          
      });
    },
    // 编辑
    edit(row){
      const parameter = {...row};
      this.dialogTitle='编辑';
      this.dialogVisible=true;
      this.ruleForm=parameter;
      console.log(parameter);
    },
    // 删除
    del(row){
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });          
      });
    },
    // 功能配置列表删除功能
    delFun(row){
      this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });          
      });
    },
    // 调整顺序
    adjustTheOrder(row){
      this.dialogVisible1=true;
      this.ruleForm1=row;
    },
    // 弹窗编辑保存
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!');
          this.dialogVisible=false;
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.dialogVisible=false;
    },
  }
}
</script>

<style lang="scss" scoped>
  .list-search-tip{
    width:30%;
    text-align: right;
  }
  .list-search-input{
    width: 70%;
  }
  .list-add{
    margin-top: 20px;
    margin-bottom: 20px;
  }
  .paging{
    width: 100%;
    margin-top: 20px;
    text-align: right;
  }
</style>

